
import gradio as gr
def plus(i):
    return i + 1
def substract(i):
    return i - 1
def split(i):
    return 1 if i > 0 else -1

with gr.Blocks() as demo:
    n1 = gr.Number(label="n1")
    n2 = gr.Number(label="n2")
    n3 = gr.Number(label="n3")
    n4 = gr.Number(label="n4")

    btn = gr.Button("计算")
    # success，只有前面成功才会执行后面
    btn.click(plus, inputs=n1, outputs=n2).success(substract, inputs=n2, outputs=n3).success(split, inputs=n3, outputs=n4)

if __name__ == "__main__":
    demo.launch()